import Layout from '../layout/Layout.vue'
import {createRouter, createWebHistory} from "vue-router";


export const constantRoutes = [
    {path: '/', redirect: '/Enter' },
    {path: '/Enter', name: 'Enter', component: () => import("@/views/Enter")},
    {path: '/Login', name: 'Login', component: () => import("@/views/Login")},
    {path: '/Register', name: 'Register', component: () => import("@/views/Register")},
    {
        path: '/Layout', name: 'Layout', component: Layout, children: [
            // 管理员平台
            {path: '/adminHome', name: 'AdminHome', component: () => import("@/views/AdminHome")},
            {path: '/adminSelfInfo', name: 'AdminSelfInfo', component: () => import("@/views/AdminSelfInfo")},
            {path: '/tenantInfo', name: 'TenantInfo', component: () => import("@/views/TenantInfo")},
            {path: '/landlordInfo', name: 'LandlordInfo', component: () => import("@/views/LandlordInfo")},
            {path: '/houseAudition', name: 'HouseAudition', component: () => import("@/views/HouseAudition")},
            {path: '/houseDelete', name: 'HouseDelete', component: () => import("@/views/HouseDelete")},
            {path: '/commentManagement', name: 'CommentManagement', component: () => import("@/views/CommentManagement")},
            {path: '/adminAuditionHouseDisplay', name: 'AdminAuditionHouseDisplay', component: () => import("@/views/AdminAuditionHouseDisplay")},
            
            
        ]
    },
    // 租客首页
    {path: '/tenantHome', name: 'TenantHome', component: () => import("@/views/TenantHome")},
    {path: '/tenantSelfInfo', name: 'TenantSelfInfo', component: () => import("@/views/TenantSelfInfo")},
    {path: '/TenantFavorite',name: 'TenantFavorite', component: () => import("@/views/TenantFavorite")},
    {path: '/SelectHouse', name: 'SelectHouse', component: () => import("@/views/SelectHouse")},
    {path: '/houseDisplay', name: 'HouseDisplay', component: () => import("@/views/HouseDisplay")},
    {path: '/tenantApplication', name: 'TenantApplication', component: () => import("@/views/TenantApplication")},
    {path: '/favoriteHouseDisplay', name: 'FavoriteHouseDisplay', component: () => import("@/views/FavoriteHouseDisplay")},
    {path: '/tenantApplicationHouseDisplay', name: 'TenantApplicationHouseDisplay', component: () => import("@/views/TenantApplicationHouseDisplay")},
    {path: '/tenantRecord', name: 'TenantRecord', component: () => import("@/views/TenantRecord")},
    {path: '/homeDisplay', name: 'HomeDisplay', component: () => import("@/views/HomeDisplay")},
    {path: '/vectorDatabase', name: 'VectorDatabase', component: () => import("@/views/VectorDatabase")},
    {path: '/personalAssistant', name: 'PersonalAssistant', component: () => import("@/views/PersonalAssistant")},
    {path: '/graphRAGAssistant', name: 'GraphRAGAssistant', component: () => import("@/views/GraphRAGAssistant")},
    
    // 房东首页
    {path: '/landlordHome', name: 'LandlordHome', component: () => import("@/views/LandlordHome")},
    {path: '/landlordHouse', name: 'LandlordHouse', component: () => import("@/views/LandlordHouse")},
    {path: '/landlordSelfInfo', name: 'LandlordSelfInfo', component: () => import("@/views/LandlordSelfInfo")},
    {path: '/landlordTransactionRecord', name: 'LandlordTransactionRecord', component: () => import("@/views/LandlordTransactionRecord")},
    {path: '/applicationAudition', name: 'ApplicationAudition', component: () => import("@/views/ApplicationAudition")},
    {path: '/allHouses', name: 'AllHouses', component: () => import("@/views/AllHouses")},
    {path: '/landlordHouseDisplay', name: 'LandlordHouseDisplay', component: () => import("@/views/LandlordHouseDisplay")},
    {path: '/myHouseDisplay', name: 'MyHouseDisplay', component: () => import("@/views/MyHouseDisplay")},
    {path: '/landlordHomeDisplay', name: 'LandlordHomeDisplay', component: () => import("@/views/LandlordHomeDisplay")},
]
const router = createRouter({
    routes: constantRoutes,
    history: createWebHistory(process.env.BASE_URL)
})

// router.beforeEach((to, from, next) => {
//     const token = window.sessionStorage.getItem('userInfo');

//     if (!token) {
//         return next('/Login')
//     }

//     if (to.path === '/Login') {
//         return next();
//     }
//     if (to.path === '/Enter') {
//         return next();
//     }
//     if (to.path === '/Register') {
//         return next();
//     }
//     if (to.path === '/adminHome') {
//         return next();
//     }
//     if (to.path === '/tenantHome') {
//         return next();
//     }
//     if (to.path === '/landlordHome') {
//         return next();
//     }

//     if (to.path === '/tenantInfo') {
//         return next();
//     }

//     if (to.path === '/landlordInfo') {
//         return next();
//     }

//     if (to.path === '/houseAudition') {
//         return next();
//     }

//     if (to.path === '/houseDisplay') {
//         return next();
//     }

//     if (to.path === '/houseDelete') {
//         return next();
//     }
    
//     if (to.path === '/' && token) {
//         if(window.sessionStorage.getItem('identity') === 'admin'){
//             return next('/adminHome')
//         }else if(window.sessionStorage.getItem('identity') === 'tenant'){
//             return next('/tenantHome')
//         }else if(window.sessionStorage.getItem('identity') === 'landlord'){
//             return next('/landlordHome')
//         }
//     }

//     next()
// })

export default router
